homepage Welcome to WebmasterWorld Guest from 54.205.144.54
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

    
If checkbox checked problem
zorro




msg:4204841
 4:09 pm on Sep 21, 2010 (gmt 0)

NOT SURE WHAT CATEGORY THIS FALLS UNDER?

I am using the following piece of code to open a new window when a checkbox is checked...

<INPUT type="checkbox" name="name" value="YES" onClick="window.open('/somepage.php?do=something&id=<?php echo $SOMEID["id"] ?>','','width=600,height=350,left=100,top=100,screenX=100,screenY=100')">

The page opens ok when the checkbox is ticked (checked).

PROBLEM:
The page opens again if the checkbox is un-ticked (un-checked).

I just want to open the page if the checkbox is ticked only but not sure how to do this?

OTHER INFO:
Seperate checkboxes are dynamically created on the page for each id=<?php echo $SOMEID["id"] ?>

 

Fotiman




msg:4204968
 8:11 pm on Sep 21, 2010 (gmt 0)

onClick="if(this.checked) {window.open('/somepage.php?do=something&id=<?php echo $SOMEID["id"] ?>','','width=600,height=350,left=100,top=100,screenX=100,screenY=100');}">

zorro




msg:4205001
 9:16 pm on Sep 21, 2010 (gmt 0)

Fotiman you are the 'Man'!

A million thanks!

zorro




msg:4205003
 9:26 pm on Sep 21, 2010 (gmt 0)

Dear Fotiman - just a thought but would it be possible to close the same window that was opened using what you supplied above only using..

if (this.unchecked) {window.close etc ?

Something like this...

<INPUT type="checkbox" name="name" value="YES" onClick="if(this.checked) {window.open('/somepage.php?do=something&id=<?php echo $SOMEID["id"] ?>','','width=600,height=350,left=100,top=100,screenX=100,screenY=100');} if (this.unchecked) {window.close('/somepage.php?do=something&id=<?php echo $SOMEID["id"] ?>');}">

Fotiman




msg:4205268
 1:45 pm on Sep 22, 2010 (gmt 0)

onClick="if(this.checked) {w = window.open('/somepage.php?do=something&id=<?php echo $SOMEID["id"] ?>','','width=600,height=350,left=100,top=100,screenX=100,screenY=100');}else{w.close();}">

Ideally, you should probably not define this script inline, as it will be harder to maintain and less efficient. You might do something like this instead:

<script type="text/javascript">
var WindowMgr = {
_w: {},
checkboxHandler: function (el, id) {
var wId = 'window' + id,
w = this._w[wId];
if (el.checked) {
w = window.open('/somepage.php?do=something&id=' + id,
wId,
'width=600,height=350,left=100,top=100,screenX=100,screenY=100');
}
else {
if (w) {
w.close();
}
}
this._w[wId] = w;
}
};
</script>
<INPUT type="checkbox" name="name" value="YES" onclick="WindowMgr.checkboxHandler(this,<?php echo $SOMEID["id"]?>);">
<INPUT type="checkbox" name="name" value="YES" onClick="WindowMgr.checkboxHandler(this,<?php echo $SOMEID["id"]?>);">

Fotiman




msg:4205270
 1:49 pm on Sep 22, 2010 (gmt 0)

Note, the first method I gave above will cause the same window to be opened/closed regardless of what checkbox was checked, so if user checks checkbox 1, window opens, then user checks checkbox 2, and the first window is replaced by the window for the 2nd checkbox, then user unchecks checkbox 1 and the window opened for checkbox 2 will go away, so if user then unchecks checkbox 2, there will be a javascript error because w is not defined. The second method I posted will create a new window for each checkbox, and unchecking the first checkbox would close only the window that was opened by the first checkbox.

zorro




msg:4206166
 2:02 am on Sep 24, 2010 (gmt 0)

That's brilliant Fotiman!

I'm sure this will help other too as I have come across others with similar problem trawling the internet.

many thanks!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved