/    Sign up×
Community /Pin to ProfileBookmark

Hi,

below is the HTML table. There are 2 columns first is a URL and second one is CheckedBox. I need if the checkbox is checked URL opens in new window and if the checkbox is not checked it opens in the same window. This table will fille dynamically . and i want to do it through JavaScript.

[code]

<table id=”myTB”>
<tr>
<td class=”ms-vb”><a href=”http://google.com” onclick=”validatechk();”>Testing Google Site</a></td>
<td class=”ms-vb”><input type=”checkbox”></td>
</tr>

<tr>
<td class=”ms-vb”><a href=”http://msn.com” onclick=”validatechk();”>msn</a></td>
<td class=”ms-vb”><input type=”checkbox”></td>
</tr>

<tr class=”ms-alternating”>
<td class=”ms-vb”><a href=”http://asiem.com/blog” onclick=”validatechk();”>asimsse blog</a></td>
<td class=”ms-vb”><input type=”checkbox” ></td>
</tr>

</table>
[/code]

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@KorOct 08.2010 — I need if the checkbox is checked URL opens in new window [COLOR="Red"]and if the checkbox is not checked it opens [/COLOR]in the same window. [/QUOTE]
Eeeer, how's that? JavaScript functions are triggered by events which follow the user's actions. The absence of an action ("and if the checkbox is not checked") generates no event, so what to do? Can you detail a little bit your aim?

And: do you know JavaScript? At least at a basic level? Have you tried to write that function? I see no JavaScript code in your post.
Copy linkTweet thisAlerts:
@asimnadeemauthorOct 08.2010 — thanks for replying, i am new to javaScript. i am trying to solve it by following

http://www.w3schools.com/JS/js_ex_dom.asp

any idea?
Copy linkTweet thisAlerts:
@KorOct 08.2010 — Well. it would be more useful for you to tell us what you want to do, not what you have followed to solve... to solve what? can you post your problem in simple, concise words, please?
Copy linkTweet thisAlerts:
@asimnadeemauthorOct 08.2010 — I Have table with 2 columns

===============================

Google checkbox = Checked

_________|__________________________

msn checkbox = UnChecked

_
__
______|_________________________

asimsse checkbox = checked

_
__
______|_________________________

now i want when some one click on "Google" and the checkbox value is checked then it opens the google link in new window. document.GetValuebyID() is not an option. let me know is it clear.



<table id="myTB">
<tr>
<td><a href="http://google.com">Google</a></td>
<td><input type="checkbox" Checked="Checked"></td>
</tr>

<tr>
<td><a href="http://msn.com">msn</a></td>
<td><input type="checkbox"></td>
</tr>

<tr>
<td><a href="http://asiem.com/blog">asimsse</a></td>
<td><input type="checkbox" Checked="Checked"></td>
</tr>

</table>
Copy linkTweet thisAlerts:
@FangOct 09.2010 — [CODE]onclick="return validatechk(this);"[/CODE]
[CODE]function validatechk(obj) {
var box = obj.parentNode.parentNode.getElementsByTagName('input')[0];
if(box.checked) {window.open(obj);}
else {location.href = obj;}
return false;
}
[/CODE]
Copy linkTweet thisAlerts:
@Sterling_IsfineOct 09.2010 — The usual way to do this is simply to have an adjacent link that opens the same URL in a new window. The 'new window' link is often represented by a suggestive symbol.

Use of checkboxes is script-dependent. This solution sets the target of the clicked link so that user preferences are followed:[CODE]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Checkbox Selects Link Target</title>
</head>
<body style="font-family: Arial;border: 0 none;">
<p>
<table id="myTB">
<tr>
<td><a href="http://google.com" id='gLink'>Google</a></td>
<td><input type="checkbox" Checked="Checked" id='gLinkCB'></td>
</tr>

<tr>
<td><a href="http://msn.com" id='mLink'>msn</a></td>
<td><input type="checkbox" id='mLinkCB'></td>
</tr>

<tr>
<td><a href="http://asiem.com/blog" id='aLink'>asimsse</a></td>
<td><input type="checkbox" Checked="Checked" id='aLinkCB'></td>
</tr>
</table>

<script type='text/javascript'>

function selectTarget()
{
var args = selectTarget.arguments;

for( var i = 0; i < args.length; i++ )
document.getElementById( args[ i ] ).onclick = checkBox;

function checkBox()
{
this.target = document.getElementById( this.id + 'CB' ).checked ? '_blank' : '_self';
}
}

selectTarget( 'gLink', 'mLink', 'aLink' );

</script>

</body>
</html>[/CODE]
×

Success!

Help @asimnadeem spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...