Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-17-2012, 10:43 PM   PM User | #1
deafdigit
New Coder

 
Join Date: Jul 2009
Location: Odense, Denmark
Posts: 70
Thanks: 4
Thanked 0 Times in 0 Posts
deafdigit is an unknown quantity at this point
Dynamic JQuery UI dialogs

Alright so I've seen something like this question around, but I can't really figure out how to make it right...

With a php-loop I'm building a table. Each row of this table represents a question and contains a cell with a link which is supposed to open a JQuery UI-dialog with a standard form in it allowing the user to answer that question.

Now here's the tricky bit. When the user has answered the question the answer need to be submitted to a MySQL-db and it needs the question's id so as to map the two together.

My idea so far is to give the form a <input type='hidden' name='id'> element and make the value-attribute contain the id of the question. However, I can't figure out how to get the id into this input-element.

I can of course put the question's id into the link's id-attribute like this:

PHP Code:
<a href='javascript:void(e);' id='1'>Answer</a
... but I don't know how to get it into the form's hidden input field.

Can somebody please help me with this?


Thank you in advance,

// deafdigit
__________________
HornskovVindberg inkasso
deafdigit is offline   Reply With Quote
Old 12-18-2012, 05:17 PM   PM User | #2
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
how are you submitting each question? via ajax? if so lets see the code for that.

oh also, ID's should never start with a numeric value
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Old 12-18-2012, 08:35 PM   PM User | #3
deafdigit
New Coder

 
Join Date: Jul 2009
Location: Odense, Denmark
Posts: 70
Thanks: 4
Thanked 0 Times in 0 Posts
deafdigit is an unknown quantity at this point
Well the question thing was just an example. Let's keep it simple.

I want this link

PHP Code:
<a href='javascript:void(e);' id='a1'>Link</a
to open a dialog containing a form with this hidden element

PHP Code:
<input type='hidden' name='id' value='a1' /> 
Each link is generated with a php-loop. Let's say like this:

PHP Code:
<?php
for($i=0$i<10$i++)
{
?>
    <a href='javascript:void(e);' id='a<?php echo $i?>'>Link</a>
<?php
}
?>
... or something to that effect. Now, of course I could just include a

PHP Code:
<div id='a<?php echo $i?>'></div>
in the php-loop and then use that as the target for the dialog, but that just seems kind of a brute-force-sort-of-not-very-pretty way to do it.

So I was wondering if there is any way to just make one <div> with the <input type='hidden'>-element in it and then pass the ID-attribute of the clicked link to that.

I don't know if I'm making any sense
__________________
HornskovVindberg inkasso

Last edited by deafdigit; 12-18-2012 at 08:42 PM..
deafdigit is offline   Reply With Quote
Old 12-18-2012, 11:30 PM   PM User | #4
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
give all the links the same class, say myclass

with jquery:


Code:
$('.myclass').on('click', function(){
$('body').remove("#tempdiv");
$('body').append("<div id='tempdiv'><form><input type='hidden' name='id' value='"+this.id"' /></form>")
 $( "#tempdiv" ).dialog();

});
then use jquery to take over the form submission using .submit() and on a successful submittal, use
Code:
$('#tempdiv').dialog('close')
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Old 12-25-2012, 04:22 PM   PM User | #5
deafdigit
New Coder

 
Join Date: Jul 2009
Location: Odense, Denmark
Posts: 70
Thanks: 4
Thanked 0 Times in 0 Posts
deafdigit is an unknown quantity at this point
Took me a little while to get this tested properly but is exactly what I needed.

Thanks a lot DanInMa.

Merry Christmas.
__________________
HornskovVindberg inkasso
deafdigit is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:50 AM.


Advertisement
Log in to turn off these ads.