Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to

Status
Not open for further replies.

alan123

MIS
Joined
Oct 17, 2002
Messages
149
Location
US
I want to know how to pass the dynamic values, for example I have the php code:
======
<?php

for ($i=0;$i<10;$i++) {
<input type=text name=name[$i]>
<input type=button onClick=(will show the value in textbox)>
}
?>
======

This will create 10 textboxes and 10 buttons, how can I write code so when I enter text in box1 (for example) then click button1 to pop up this text value(javascript:alert())? can anyone help me on it, thanks very much in advance.
 
This is a javascript question.
As for your php code. You need to tell php to output your <input> tags to the clients browser:
Code:
<?php

for ($i=0;$i<10;$i++) {
echo &quot;<input type=text name=name[$i]><br>\n&quot;;
echo &quot;<input type=button onClick=(will show the value in textbox)><br>\n&quot;;
}
?>
 
I already did what you mentioned, but for button &quot;onClick&quot; event how to pass those text value and display it as message?
 
Let's be kind and help alan123:
I'd do it differently - without an array since it's easier to address distinct named objects:
Code:
<?php
for ($i=0;$i<10;$i++) {
echo &quot;<input type=\&quot;text\&quot; name=\&quot;text$i\&quot;><br>\n&quot;;
echo &quot;<input type=\&quot;button\&quot; name=\&quot;button$i\&quot; onClick=\&quot;alert(document.form.text$1.value)\&quot;><br>\n&quot;;
}
?>
You also want to double quote all attributes in HTML for correct validation. The example assumes that the form is name 'form'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top