LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-06-2006, 03:06 PM   #1
mohit dhawan
Member
 
Registered: Mar 2005
Posts: 92

Rep: Reputation: 15
embedding javascript in url


actully what i need to do is select particular options in a page through url;

ie for eg: if ther is a checkbox,, if i click on a particular link it shud be selected can anyone help me witht the script,.


Thank you.
 
Old 04-06-2006, 04:02 PM   #2
toreric
Member
 
Registered: Dec 2005
Location: Tväråmark, Sweden
Distribution: Debian/Kubuntu
Posts: 105

Rep: Reputation: 27
Your question is impossible to understand, please be clear. Are you trying to design a web page having checkboxes (for what purpose)? If so, how is Javascript involved?
 
Old 04-06-2006, 04:13 PM   #3
mohit dhawan
Member
 
Registered: Mar 2005
Posts: 92

Original Poster
Rep: Reputation: 15
I mean I need not have to explicityly have to click on the check box, to select it.

better example;

u have a certain multiple choice question on ur webpage and chkboxes to mark the answers.
now i want to select the particular checkbox by entering javascript in the adress bar(ie i write the javascript wher we type the url)
and the appropriate checkbox gets selected.

thst the best I can Explain.

thank you.
 
Old 04-06-2006, 04:22 PM   #4
toreric
Member
 
Registered: Dec 2005
Location: Tväråmark, Sweden
Distribution: Debian/Kubuntu
Posts: 105

Rep: Reputation: 27
Cannot imagine how that would be possible! You should check the box with a mouse click, or use the tab key to move to the check box (if you haven't got a mouse) and then check it using the space bar or so. Is this, by the way, a LinuxQuestions topic?
 
Old 04-06-2006, 04:25 PM   #5
nickj6282
Member
 
Registered: Mar 2006
Location: Fond du Lac, Wisconsin, USA
Distribution: Debian
Posts: 51

Rep: Reputation: 15
This almost works in FF and works even less well in IE when I tried it (but it does sort of work):

Code:
javascript:document.getElementById('checkbox').checked=true;
try it and see if it works for you.

But if you want to pass variables to a page through a GET request (in the URL) then you're going to need to use some kind of server-side language (like PHP) to output the correct Javascript code to your webpage. Or better yet, just have it write out the checkbox data with the value="checked" option.

-Nick
 
Old 04-06-2006, 04:28 PM   #6
astorm
LQ Newbie
 
Registered: Nov 2005
Distribution: Slackware
Posts: 23

Rep: Reputation: 15
Code:
<html>
<head>
<script language="Javascript">
function checkIt()
{
  document.getElementById("check").click();
}
</script>
</head>
<body>
<input type="checkbox" name="check" id="check" value="Checkbox">
<input type="button" value="Check it!" onClick=checkIt()>
</body>
</html>
Works on Firefox 1.5.
 
Old 04-06-2006, 11:41 PM   #7
nickj6282
Member
 
Registered: Mar 2006
Location: Fond du Lac, Wisconsin, USA
Distribution: Debian
Posts: 51

Rep: Reputation: 15
Awesome. Works from the address bar too.
 
Old 04-07-2006, 10:41 AM   #8
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Rep: Reputation: 32
Here is a more general solution, then when it loads the page, it will be clicked if the address is like, http://www.somesite.com/page/asdf.html?checkthebox=1

Code:
<script>
window.location.href.match(/(^[^\?]+\?)(.*)$/);

params = RegExp.$2.split(/\&/);
for(var i = 0; i < params.length; i++) {
	var tmp = params[i].split(/\=/);
	params[i] = [tmp[0], tmp[1]];
}

for(var i = 0; i < params.length; i++) {
	if(params[i][0] == "checkthebox" && params[i][1] == "1")
		document.getElementById('checkbox').checked=true;

}
</script>

Last edited by 95se; 04-07-2006 at 10:42 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR The requested URL could not be retrieved While trying to retrieve the URL: /re Niceman2005 Linux - General 1 06-29-2005 09:51 AM
embedding a command for at? Xstack Linux - General 2 02-21-2005 03:42 PM
Javascript : Importing content from another url synna Programming 0 03-02-2004 11:12 AM
embedding applications using qt ankitgdit Programming 1 10-26-2003 10:46 AM
Gimp::Embedding Url Links in Images rootyard Linux - Software 1 08-17-2003 02:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration