...

View Full Version : checkbox issues



cyberninja
09-29-2011, 01:35 AM
what would i need to do to get checkbox to correspond to page im submitting to
heres what i have so far


[CODE]

<script type = "text/javascript">
function newPage(page) {
if (document.getElementById("chk1").checked) {
OpenWin = this.open(page,"CtrlWindow","top=80,left=100,screenX=100,screenY=80,width=550,height=460,toolbar=no,menubar=no,location=no, scrollbars=no,resizable=yes");
return false;
}
}


function closepop() {if (OpenWin != null) OpenWin.close() }
window.onunload = closepop;

</script>
</head>
<body>
<form name=”form” id=”form” action=”” method=”post”>
happy<input type=”text” name=”happy” id=”happy”/>
sad<input type=”text” name=”sad” id=”sad”/>
<input type=”submit” value=”submit”/>
</form>

<input type = "checkbox" name = "chk1" id = "chk1" onclick = "newPage('randomnewpage.com')">
<INPUT TYPE=SUBMIT VALUE="submit">

[CODE]


the problem with this it always opens the page when i click the checkbox and does not send that values from the form to the page that opens

what i cant seem to figure out is how to send the values from the form to the new page.
And when i hit the submit button its opens the submitted form data to the webpage that the checkbox designates instead of opening the new page when i click the checkbox and not waiting for the submit button.

is there a way i can get the checkbox to do those things or will i need to use something other than javascript for those functions

Old Pedant
09-29-2011, 02:18 AM
I don't believe this part of your post:


And when i hit the submit button its opens the submitted form data to the webpage that the checkbox designates
When you hit the submit button, it will send the data to the *SAME PAGE* that you are looking at. That is, the form posts to itself.

Except that you can't use method="post" when submitting to an HTML page. You can only use post for submitting to server side code (PHP/ASP/JSP/etc.).

Old Pedant
09-29-2011, 02:19 AM
Questions for you:

(1) Do you intend to submit the <form> to anything *OTHER* than the popup page designated by the checkbox?

(2) Do you intend to have more than one checkbox, with each one popping up a different page?

cyberninja
09-29-2011, 02:45 AM
the <form> only goes to the pop up page

and yes i will have more than one checkbox each to a distinct page, 3 though possibly 4 different pages

Old Pedant
09-29-2011, 06:20 AM
Okay, step 1 is to *get* to the different pages with the form data:


<script type = "text/javascript">
var OpenWin = null;
function newPage(cb)
{
var form = cb.form;
form.action = cb.value;
OpenWin = window.open("",
"CtrlWindow",
"top=80,left=100,screenX=100,screenY=80,width=550,height=460,
toolbar=no, menubar=no,location=no, scrollbars=no,resizable=yes");
form.submit();
}

function closepop()
{
if (OpenWin != null) OpenWin.close();
}
window.onunload = closepop;
</script>
</head>
<body>
<form target="CtrlWindow" method=”get”>
happy<input type=”text” name=”happy” />
sad<input type=”text” name=”sad” >
<label>
<input type = "checkbox" value="randomnewpage.html" onclick="newPage(this);"/>
ONE
</label>
<label>
<input type = "checkbox" value="anotherpage.html" onclick="newPage(this);"/>
TWO
</label>
<label>
<input type = "checkbox" value="stillmore.html" onclick="newPage(this);"/>
THREE
</label>
</form>

Try that.

Change your popup specifcation from location=no to location=yes and you'll be able to see that the information in the <form> (the values of happy and sad) are being passed in the query string to the popup.

The next part is learning how to read the query string values via JavaScript so you can use those values in the popup.

Give me an example of what you would do with them.

cyberninja
09-30-2011, 06:59 AM
thanks, actually ive decided to change the layout of the website for now until i get a better grasp on javascript. its helpful though since it gives me an idea of where i need to get in understanding of javascript at least.

thanks again



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum