Not sure how to explain this but I'm trying to open a new window and at the same time setting a particular radio button on the opened page.
Contact-us.php (my page to Open)
<form name="f2" method="post" action="send_form_email3.php" id="Homeform1" onsubmit="return checkEmail(this)">
<input type="radio" name="package" value="Option1"> Basic
<input type="radio" name="package" value="Option2"> Silver
<input type="radio" name="package" value="Option3"> Gold
<input type="radio" name="package" value="Custom"> Custom
This is the page with the button
Home.php
<a href="javascript:win1=window.open('contact-us.php'); setCheckedValue(win1.document.forms['f2'].elements['package'], 'Option2');" id="link2" class="links"></a>
and this is the JS file
function setCheckedValue(radioObj, newValue) {
if(!radioObj)
return;
var radioLength = radioObj.length;
if(radioLength == undefined) {
radioObj.checked = (radioObj.value == newValue.toString());
return;
}
for(var i = 0; i < radioLength; i++) {
radioObj[i].checked = false;
if(radioObj[i].value == newValue.toString()) {
radioObj[i].checked = true;
}
}
}
So it works for the same page, if I put my form on the same page as the button (home.php)
However currently all the code does is open a n开发者_如何学JAVAew page!(Contact-us.php)
I'm not 100% sure this can be done but my ultimate goal is to open a new page, with the radio option already selected when the user clicks an image.
P.S this is not the full code as I only posted the partd I feel relevant.
You can pass parameters to contact-us.php?checkedValue=...
and read them either with php or Javascript.
Or you can have a Javascript code inside contact-us.php
that will read some value in the parent window, something like parent.yourGlobalObject.checkedValue
精彩评论