LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 12-30-2005, 07:49 PM   #1
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
javascript question


I'm trying to implement something and unfortunately, it seems like I need javascript, which I don't know and I don't have time to learn.
Let's hope someone of you can post me some sample code.

I have some links in a page that are created dynamically with php. php reads the result of Mysql query:
SELECT Name,Code FROM <a table> Where <kjdhfjdsh>
and creates a table of links that looks like this:

Code:
<a href=sql.php?Code="code_from_query">"Name_from_query"</a>
Is it possible to add some checkboxes lets say a,b,c
and post the value without having a submit button, but by updating all the links to look like this:

Code:
href=sql.php?Code="code_from_query"&a=[1|0]&b[1|0]&c=[1|0]
1 if the boxes are ticked and 0 if not

THANX
 
Old 01-03-2006, 03:01 PM   #2
pnellesen
Member
 
Registered: Oct 2004
Location: Missouri, USA
Distribution: Slackware 12.2, Xubuntu 9.10
Posts: 371

Rep: Reputation: 31
Yes, that's possible, but somewhat involved. The following is all off the top of my head: Basically, you'd first set the "METHOD" attribute of your form tag to "POST" and add a "name" or "id" attribute to it as well, and then add a "name" or "id" value to your checkboxes (in your case, "a", "b", and "c"). Then, you'd create a javascript function which would be called when a user selected a link (href="javascript:sendValues()" or something like that). Your Javascript function would then record the "Checked" property of each checkbox that has the name/id value of the checkboxes in question by appending it to a string which would become the queryString value of your url. Next, you would set the form.action property to the url you want to post to (with the appropriate query string appended to it), and then finally fire off the "form.submit()" method for your form. Something like this:

Code:
<script language="JavaScript">

function sendValues() {
	var qString = "?a=" + document.myForm.a.checked + "&b=" + document.myForm.b.checked + "&c=" + document.myForm.c.checked;
	document.myForm.action = document.myForm.action + qString;
	document.myForm.submit();
}

</script>
The form would look something like this:

Code:
<form name="myForm" action="myresult.html" method="POST">

<h2>Some checkboxes</h2>
A) <input type="checkbox" name="a"/><br/>
B) <input type="checkbox" name="b"/><br/>
c) <input type="checkbox" name="c"/><br/>

Click the link:

<a href="javascript:sendValues()">Send the values</a>
</form>
Again, this is all off the top of my head, there are probably better ways to do this - you may want to get a quick JavaScript primer from something like this: http://www.irt.org/xref/index.htm

Hope this helps a little.

Last edited by pnellesen; 01-03-2006 at 03:47 PM.
 
Old 01-20-2006, 12:29 AM   #3
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Original Poster
Rep: Reputation: 53
Actually I kind of used something like what you suggested for another problem in the same project.

instead of doing something like this:
Quote:
function sendValues() {
var qString = "?a=" + document.myForm.a.checked + "&b=" + document.myForm.b.checked + "&c=" + document.myForm.c.checked;
document.myForm.action = document.myForm.action + qString;
document.myForm.submit();
}
I did something like:
Quote:
function sendValues() {
var qString = "?a=" + document.myForm.a.checked + "&b=" ....
this.document.location.href= "display_query.php" + qString;
}
Thanks for the reply.....
 
  


Reply



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
He, ANOTHER javascript question Squall Programming 3 01-27-2004 06:10 PM
Javascript question unimaginative Programming 3 01-26-2004 02:32 PM
JavaScript Question jacksmash Programming 8 12-23-2003 05:01 PM
Javascript question? mikeshn Programming 2 08-22-2002 03:44 PM
JavaScript Question vance Programming 2 04-14-2002 12:30 PM

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

All times are GMT -5. The time now is 02:25 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