PDA

View Full Version : How to fetch the value of dynamic controls in asp


vkdixit
03-23-2009, 07:44 AM
Hi all,
I want to fetch the input box value which is dynamically added on asp page using javascript/jquery....

Code is:
<html>
<script src="../Contacts/cmailer/include/jquery.js" type="text/javascript"></script>
<SCRIPT LANGUAGE="JavaScript">


function addphone()
{
$("div#addnewtagP").before('<form autocomplete="off"><input type="text" id="suggest_addtag" />&nbsp;&nbsp;<select name="select_phone"><option>select one</option><option>Home</option><option>Work</option><option>Other</option></select></form>');

}

function addemail()
{
$("div#addnewtagE").before('<form autocomplete="off"><input type="text" id="suggest_addtag" />&nbsp;&nbsp;<select name="select_phone"><option>select one</option><option>Home</option><option>Work</option><option>Other</option></select></form>');

}

</SCRIPT>
<body>
<form>
<div id="addnewtagP"><a href="javascript:addphone()">Add another</a></div><br>
<div id="addnewtagE"><a href="javascript:addemail()">Add another</a></div><br>
</form>
</body>
</html>


but in this code all the text box have same value, how can i differ one from another....
plese help

Old Pedant
03-23-2009, 08:00 AM
Don't give them all the same name.

Also, as I read that code, you aren't REALLY giving the text fields ANY NAME AT ALL.

And if you don't give them a name, then THE VALUES ARE NOT SENT TO THE NEXT PAGE.

This is how HTML works. Has nothing directly to do with ASP. In fact, it's used by many people as a way to have form fields that are *NOT* sent to the next page, on purpose.

By the way, did you notice that your code adds a new *PHONE* <select> for both phone and email???

Actually, the more I look at that code, the less sense it makes. It looks like it is adding a *COMPLETE <FORM>...</FORM>* each time you hit the function. But that means it will NEVER work, because *ALL* your form fields need to be in *ONE* <FORM> in order to post to the next page.

Again, this is an HTML requirement, not ASP per se.

Again, you are asking a JavaScript question, not an ASP question.

Finally, a note: Although I still think the best way to do this is to give a different name (just add a sequence number to the base name) to each pair of text/select fields, you *CAN* get them in ASP even if they have the same name.

<%
For i = 1 To Request.Form("select_phone").Count
phoneChoice = Request.Form("select_phone")(i)
...
Next
%>


But get your JavaScript working first--ask in the JS forum if you need help--and then let's talk about the ASP aspects.

shakir
03-29-2009, 03:40 PM
but in this code all the text box have same value, how can i differ one from another....
To distinguish each object u has to add some count in it may be in name or in value...

Old Pedant
03-29-2009, 09:26 PM
Shakir: Why do you come along ONE WEEK LATER and give the SAME ANSWER other people have already given??