jeff5656 Posted August 15, 2009 Share Posted August 15, 2009 Here's part of the form: <select name = "pulmonologist" > <option selected="" value="">---Select--- <option value="none">None</option> <?php while ($row2 = mysql_fetch_assoc ($results2)) { ?><option value = "<?php echo $row2['staff_name'];?>"><?php echo $row2['staff_name'];?></option> <?php } ?> </select> Ok now I want to echo the value that the user selects in the SAME page (i.e. before the submit button is pressed) like this: <input type="submit" value = "Contact <?php echo $pulmonologist;?>" /> Do you have any thoughts on how to do this? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/170396-echo-a-variable-in-a-form-based-on-user-selection/ Share on other sites More sharing options...
smerny Posted August 15, 2009 Share Posted August 15, 2009 you can't do it with php, you'd have to use javascript Quote Link to comment https://forums.phpfreaks.com/topic/170396-echo-a-variable-in-a-form-based-on-user-selection/#findComment-898868 Share on other sites More sharing options...
jeff5656 Posted August 15, 2009 Author Share Posted August 15, 2009 Ugh. Ok I'm off to google in search for a javascript forum (and I know nothing about javascript other than downloading pre-made js scripts, so wish me luck :-) ) Quote Link to comment https://forums.phpfreaks.com/topic/170396-echo-a-variable-in-a-form-based-on-user-selection/#findComment-898882 Share on other sites More sharing options...
smerny Posted August 15, 2009 Share Posted August 15, 2009 You'll basically have to have a function that is initiated when an option value is selected... and have that function change the value of your submit. Quote Link to comment https://forums.phpfreaks.com/topic/170396-echo-a-variable-in-a-form-based-on-user-selection/#findComment-898889 Share on other sites More sharing options...
jeff5656 Posted August 15, 2009 Author Share Posted August 15, 2009 Can you show me an example of how to do that with a function? I have (probably stupidly) avoided learning functions yet so I do not know how to go about doing that. Quote Link to comment https://forums.phpfreaks.com/topic/170396-echo-a-variable-in-a-form-based-on-user-selection/#findComment-898891 Share on other sites More sharing options...
ignace Posted August 15, 2009 Share Posted August 15, 2009 Ugh. Ok I'm off to google in search for a javascript forum (and I know nothing about javascript other than downloading pre-made js scripts, so wish me luck :-) ) We have a javascript sub-section: http://www.phpfreaks.com/forums/index.php/board,6.0.html Quote Link to comment https://forums.phpfreaks.com/topic/170396-echo-a-variable-in-a-form-based-on-user-selection/#findComment-898894 Share on other sites More sharing options...
wildteen88 Posted August 15, 2009 Share Posted August 15, 2009 How to change a submit button via select value. The first result looks promising. Quote Link to comment https://forums.phpfreaks.com/topic/170396-echo-a-variable-in-a-form-based-on-user-selection/#findComment-898897 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.