Jump to content

[SOLVED] PHP popup window upon select


pcw

Recommended Posts

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?

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 ?>

 

 

 

Link to comment
Share on other sites

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 :(

Link to comment
Share on other sites

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 :P

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.