Is there a way to call a PHP database within a *.html page and populate the answer to a hidden field? For example: SQL DB has 2 fields ID and SEGMENT,
ID SEGMENT
1 A
2 B
3 C
4 D
I have a form:
<form action="Untitled-2.php" method="post" name="form1" id="form">
<input type="radio" name="ID" value="4" />
4</label>
<label>
<input type="radio" name="ID" value="3" />
3</label>
<label>
<input type="radio" name="ID" value="2" />
2</label>
<label>
<input type="radio" name="ID" value="1" />
1</label>
<input name="segment" id="segment" type="hidden" />
I want to be able to have a button onclick() go out the the php server collect which Segment it is and populate the hidden text field "segment" then submit all on the same HTML page? Can this be done using AJAX, if so do you have the code?
populate hidden field from PHP database
Moderator: General Moderators
-
dfalkowitz
- Forum Newbie
- Posts: 1
- Joined: Tue Jul 26, 2011 4:43 pm
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: populate hidden field from PHP database
I don't quite understand what you're asking... why do you want to get this value after output but before submit?
Re: populate hidden field from PHP database
It can be done, but since you are populating this based (I'm assuming) on what is selected from the radio buttons, why not just look this data up on the script that the form submits to? Not sure what it will be used for, but from a security standpoint, if this is anything important, you must remember that setting it to a hidden field can be cahnged by the user before submitting the form.
-Greg
-Greg