Any body help me

But i am not getting values when clicking button "getValue"

my code is

<html>
<head>
<title>jQuery add / remove textbox example</title>

      <script src="jquery.min.js"></script>

<style type="text/css">
    div{
        padding:8px;
    }
</style>

</head>

<body>

<h1>jQuery add / remove textbox example</h1>

<script type="text/javascript">

$(document).ready(function() {
    var max_fields      = 10; //maximum input boxes allowed
    var wrapper         = $(".input_fields_wrap"); //Fields wrapper
    var add_button      = $(".add_field_button"); //Add button ID

    var x = 1; //initlal text box count
    $(add_button).click(function(e){ //on add input button click
        e.preventDefault();
        if(x < max_fields){ //max input box allowed
            x++; //text box increment
            $(wrapper).append('<div><input type="text" name="mytext[]"/><input type="text" name="email[]"/><input type="text" name="mobile[]"/><a href="#" class="remove_field">Remove</a></div>'); //add input box







        }
    });

    $(wrapper).on("click",".remove_field", function(e){ //user click on remove text
        e.preventDefault(); $(this).parent('div').remove(); x--;
    })


$("#getValue").click(function() {

    var arrayLength = mytext.length;
for (var i = 0; i < arrayLength; i++) {
    alert(mytext[i]);
    //Do something
}


        });


});
</script>
</head><body>
 <form name="myform" action="save1.php" method="post" enctype="multipart/form-data" >
<div class="input_fields_wrap">
    <button class="add_field_button">Add More Fields</button>
    <div><input type="text" name="mytext[]" id="mytext">
    <input type="text" name="email[]" id="email">
    <input type="text" name="mobile[]" id="mobile"></div>
</div>
<input type="button" value="getValue" id="getValue">
 <input type="submit" name="submit" />
 </form>
</body>
</html>

Do you want the button to perform the function #getValue?

No i want to get the values when clicking #getValue button

When clicking i want to get all text box values

please help to solve this problem

I will request you to try the following code. for the Function #getValue in your case, change it to something like this

function getValue()
{   
var i = 0;  
if(mytext(i))  
{  
return true;  
}  
else  
{  
//Do something;  
}  
} 


Then make sure under 
<input type="button" value="getValue" id="getValue" >
you change it to something like this
<input type="button" value="getValue" id="getValue" onClick="getValue(this);" >

When using Java coding, the action onCHANGE or OnClick is used to perform certain work. It must always be included in the input box that is inteded to call the function. And it shld also be accompanied by 'this value' to return the desired error.....

Hi Makara,
i am trying but not getting please give me code for getting values when clicking get values button.

Regards,
Ramsiva

Hi Makara,

I am getting first row values, please help me get all values using OnClick event

<html>
<head>
<title>jQuery add / remove textbox example</title>

      <script src="jquery.min.js"></script>

<style type="text/css">
    div{
        padding:8px;
    }
</style>

</head>

<body>

<h1>jQuery add / remove textbox example</h1>

<script type="text/javascript">

$(document).ready(function() {
    var max_fields      = 10; //maximum input boxes allowed
    var wrapper         = $(".input_fields_wrap"); //Fields wrapper
    var add_button      = $(".add_field_button"); //Add button ID

    var x = 1; //initlal text box count
    $(add_button).click(function(e){ //on add input button click
        e.preventDefault();
        if(x < max_fields){ //max input box allowed
            x++; //text box increment
            $(wrapper).append('<div><input type="text" name="mytext[]"/><input type="text" name="email[]"/><input type="text" name="mobile[]"/><a href="#" class="remove_field">Remove</a></div>'); //add input box


        }
        alert(x);   
    });

    $(wrapper).on("click",".remove_field", function(e){ //user click on remove text
        e.preventDefault(); $(this).parent('div').remove(); x--;
    })
  });

$(document).ready(function() {
  $( "#getValue" ).click(function() {


   var mytext=$("#mytext").val(); 
var email=$("#email").val();
var mobile=$("#mobile").val();
alert(mytext);
alert(email);
alert(mobile);

  });
});

</script>





</head><body>
 <form name="myform" action="save1.php" method="post" enctype="multipart/form-data" >
<div class="input_fields_wrap">
    <button class="add_field_button">Add More Fields</button>
    <div><input type="text" name="mytext[]" id="mytext">
    <input type="text" name="email[]" id="email">
    <input type="text" name="mobile[]" id="mobile"></div>
</div>
<input type="button" value="getValue" id="getValue">
 <input type="submit" name="submit" />
 </form>
</body>
</html>

This means you will have to use a $_GET statement in your php code or in your input button during get as follows

<a href="save1.php?vol2=<?php echo $_GET['myform'];?>">getValue</a>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.