pcw Posted March 5, 2009 Share Posted March 5, 2009 Hi, I was wondering if it was possible to create a popup window that appears when a certain value is selected from a select menu. I have this select field: Field Type: <select name="fieldtype"> <option>Text Field</option> <option>Text Area</option> <option>Radio Button</option> <option>Checkbox</option> <option>Select</option> </select><br />'; It is part of a dynamic form script that I would like to appear tidier to the user. Therefore, I would like a popup window to appear when the user selects Select from the menu. Is this possible without the user having to submit the request first? Quote Link to comment https://forums.phpfreaks.com/topic/148149-solved-php-popup-window-upon-select/ Share on other sites More sharing options...
jackpf Posted March 5, 2009 Share Posted March 5, 2009 Yes, to answer your question. But it has nothing to do with php; it's javascript. And if you actually want to know how to do it, you could do something like this- <select onchange="window.open('popup.html')"> Quote Link to comment https://forums.phpfreaks.com/topic/148149-solved-php-popup-window-upon-select/#findComment-777678 Share on other sites More sharing options...
pcw Posted March 5, 2009 Author Share Posted March 5, 2009 Hi Jack, thanks for your reply. I dont really know anything about javascript. I tried with what you suggested, but have got it wrong, and keep getting errors. Field Type: <select name="fieldtype"> <option>Text Field</option> <option>Text Area</option> <option>Radio Button</option> <option>Checkbox</option> <option onchange="window.open('addfield.php')">Select</option> </select><br />'; What should this code be? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/148149-solved-php-popup-window-upon-select/#findComment-777687 Share on other sites More sharing options...
jackpf Posted March 5, 2009 Share Posted March 5, 2009 Hey, <form> <select onchange="window.open('popup.html')"> <option>1</option> <option>2</option> </select> </form> I just tested that and it worked fine. You do need to change popup.html to the file you want to display in the new window btw. Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/148149-solved-php-popup-window-upon-select/#findComment-777695 Share on other sites More sharing options...
pcw Posted March 5, 2009 Author Share Posted March 5, 2009 Hi Jack, I only want the popup to appear if the uses clicks on the 'Select' option in the menu. The rest of the options should not do anything as the rest of the script handles them. Is that poss? Quote Link to comment https://forums.phpfreaks.com/topic/148149-solved-php-popup-window-upon-select/#findComment-777697 Share on other sites More sharing options...
jackpf Posted March 5, 2009 Share Posted March 5, 2009 Oh right...I don't really understand what you mean tbh, but is this what you want? <option onclick="window.open('addfield.php')">Select</option> Quote Link to comment https://forums.phpfreaks.com/topic/148149-solved-php-popup-window-upon-select/#findComment-777700 Share on other sites More sharing options...
pcw Posted March 5, 2009 Author Share Posted March 5, 2009 That is along the lines of what I want: <option onclick="window.open('addfield.php')">Select</option> But I get this error Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/moveitho/public_html/sitebuilder/testform1.php on line 14 If I change it to this: <option onclick="window.open(addfield.php)">Select</option> The page loads without errors but the popup doesnt appear. Do I need to include tags for javascript like you have to do with php? eg <?php and ?> Quote Link to comment https://forums.phpfreaks.com/topic/148149-solved-php-popup-window-upon-select/#findComment-777717 Share on other sites More sharing options...
jackpf Posted March 5, 2009 Share Posted March 5, 2009 You probably need to escape your quotes, like this- \' Quote Link to comment https://forums.phpfreaks.com/topic/148149-solved-php-popup-window-upon-select/#findComment-777720 Share on other sites More sharing options...
pcw Posted March 5, 2009 Author Share Posted March 5, 2009 That cured the error, but the popup does not open. Should this work fine in a PHP script? Quote Link to comment https://forums.phpfreaks.com/topic/148149-solved-php-popup-window-upon-select/#findComment-777727 Share on other sites More sharing options...
jackpf Posted March 6, 2009 Share Posted March 6, 2009 It should. Post your code and I'll have a look... Quote Link to comment https://forums.phpfreaks.com/topic/148149-solved-php-popup-window-upon-select/#findComment-777755 Share on other sites More sharing options...
pcw Posted March 6, 2009 Author Share Posted March 6, 2009 Thanks, this is the code that is from the part of the script with the prob: <?php $optionCnt = 0; if ($_POST['addoption']) { echo '<form name="makeformfield" method="post"> Field Name: <input type="text" name="fieldname" value="'.$_POST['fieldname'].'"> Field Type: <select name="fieldtype"> <option>Text Field</option> <option>Text Area</option> <option>Radio Button</option> <option>Checkbox</option> <option onClick="window.open(\'addfield.php\')">Select</option> </select><br />'; foreach($_POST as $field => $value) { if (substr($field,0,11) == "optionvalue") { $optionCnt++; echo "<input type='text' name='$field' value='$value' /><br />"; } } echo "<input type='text' name='optionvalue$optionCnt' value='' /><br />"; echo stripslashes('<textarea cols="60" rows="5" name="previewarea" >'.$_POST['previewarea'].'</textarea>'); echo '<br /><input type="submit" name="update" value="update"><input type="submit" name="submit" value="submit"> <input type="submit" name="addoption" value="addoption">'; }?> I cant understand why the popup is not working Quote Link to comment https://forums.phpfreaks.com/topic/148149-solved-php-popup-window-upon-select/#findComment-778055 Share on other sites More sharing options...
jackpf Posted March 6, 2009 Share Posted March 6, 2009 Hmm.... try changing onClick to onclick? (lower case) I'm not actually sure if it makes a difference, but it worked for me once. But apart from that, I don't see why it doesn't work. If you haven't got it working by tonight, I'll test it when I get home, because I obviously don't have PHP/Apache on my school computers Quote Link to comment https://forums.phpfreaks.com/topic/148149-solved-php-popup-window-upon-select/#findComment-778060 Share on other sites More sharing options...
kickstart Posted March 6, 2009 Share Posted March 6, 2009 Hi Not sure that "onclick" works with a particular option. While it might work in some browsers I don't think it works in IE. Think what you need to do is put the onchange event on the select itself, and call a javascript function. Within that function check the value of the select and if it is the appropriate one then do the popup. Something like this <html> <head> <script language="Javascript" type="text/javascript"> function ReactToChange() { if (document.getElementById("DropDownList").value == "Select") { window.open('popup.html') } } </script> </head> <body> <form> <select id="DropDownList" onchange="ReactToChange()"> <option value="Text Field">Text Field</option> <option value="Text Area">Text Area</option> <option value="Radio Button">Radio Button</option> <option value="Checkbox">Checkbox</option> <option value="Select">Select</option> </select> </form> </body> </html> All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/148149-solved-php-popup-window-upon-select/#findComment-778062 Share on other sites More sharing options...
jackpf Posted March 6, 2009 Share Posted March 6, 2009 Hi Not sure that "onclick" works with a particular option. While it might work in some browsers I don't think it works in IE. Think what you need to do is put the onchange event on the select itself, and call a javascript function. Within that function check the value of the select and if it is the appropriate one then do the popup. Something like this <html> <head> <script language="Javascript" type="text/javascript"> function ReactToChange() { if (document.getElementById("DropDownList").value == "Select") { window.open('popup.html') } } </script> </head> <body> <form> <select id="DropDownList" onchange="ReactToChange()"> <option value="Text Field">Text Field</option> <option value="Text Area">Text Area</option> <option value="Radio Button">Radio Button</option> <option value="Checkbox">Checkbox</option> <option value="Select">Select</option> </select> </form> </body> </html> All the best Keith Yeah, it's been stated earlier in the thread that his objective is to have a popup open when a certain option is selected, not when the option is changed. I guarantee you that <option> supports onclick, as it states this on w3.org, and it works on my computer. Quote Link to comment https://forums.phpfreaks.com/topic/148149-solved-php-popup-window-upon-select/#findComment-778066 Share on other sites More sharing options...
pcw Posted March 6, 2009 Author Share Posted March 6, 2009 Hi Jack, tried changing it to onclick, but no success. I think I will give it a go using keiths way, as I had a change of plan. Thanks to both, for your help Quote Link to comment https://forums.phpfreaks.com/topic/148149-solved-php-popup-window-upon-select/#findComment-778107 Share on other sites More sharing options...
kickstart Posted March 6, 2009 Share Posted March 6, 2009 I guarantee you that <option> supports onclick, as it states this on w3.org, and it works on my computer. A quick google for "onclick option" will give you loads of sites with people having the same issue due to some versions of IE not supporting it. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/148149-solved-php-popup-window-upon-select/#findComment-778167 Share on other sites More sharing options...
jackpf Posted March 6, 2009 Share Posted March 6, 2009 ahh...ie; it's the root of all problems... Quote Link to comment https://forums.phpfreaks.com/topic/148149-solved-php-popup-window-upon-select/#findComment-778175 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.