Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how to get the value of a specific field using .attr or other in jquery

Posted on 2011-09-27
12
Medium Priority
?
322 Views
Last Modified: 2012-05-12
HI Im trying to get the <input type name="flag" value using jquery

I thought of using .attr function on the form element but I cant figure out how to get that

(Im doing it becuase I need to check if the form is sumbitted )
<form id = "popup_form_{$row['id']}" name= "nurit" action ="" method ="post" style="background-color:white; border:2px solid blue;padding:4px; width:250px; display :none; position:absolute"  onsubmit = "return false;">

			<input type="hidden" name="id" value ="{$row['id']}">

			<input type="hidden" name ="email" value ="{$row['email_address']}">
			<input type ="hidden" name ="flag" value = "test" >

			<input type="submit" value="SpamIt" name="spamIt" style="margin-right:15px;">

			<input type="button" value="Close" onclick="closePopup()"/>

			

			</form>

Open in new window

0
Comment
Question by:Nura111
  • 6
  • 5
12 Comments
 
LVL 41

Accepted Solution

by:
guru_sami earned 668 total points
ID: 36713413
Give your element an id like:
<input type ="hidden" id="flag" value="test" >

Open in new window


Get the value like:

var x = $("#flag").val();

Open in new window

0
 
LVL 83

Assisted Solution

by:leakim971
leakim971 earned 1332 total points
ID: 36713415
you may use :
var value = $(":hidden[name='flag']").val();
alert(value);

// OR

// your way (using attr)
value = $(":hidden[name='flag']").attr("value");
alert(value);

Open in new window


test page : http://jsfiddle.net/EvrnJ/
0
 

Author Comment

by:Nura111
ID: 36713438
and also how can I set the value of this element to something else please?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 83

Expert Comment

by:leakim971
ID: 36713450
var something = 10;

$(":hidden[name='flag']").val( something  );

or

$(":hidden[name='flag']").attr("value", something);
0
 

Author Comment

by:Nura111
ID: 36713569
Hi the problem again is that I need something more uniqueI have more than one popup_form_{$row['id']}"
in the page how can I conecct to the id number of the form..
0
 
LVL 83

Assisted Solution

by:leakim971
leakim971 earned 1332 total points
ID: 36713582
var something = 10;
var popup_form_id = "popup_form_{$row['id']}";

$(":hidden[name='flag']", "#"+popup_form_id).val( something  );
0
 

Author Comment

by:Nura111
ID: 36713618
no its not working isnt the comma is adding the elements so it will chose 2 Dom element in that case?
0
 

Author Comment

by:Nura111
ID: 36713628
sorry it is working my mistake but still isnt comma is adding the elements so it will chose 2 Dom element in that case?
0
 
LVL 83

Expert Comment

by:leakim971
ID: 36713646
$("one,two")

is not

$("one" , "two")

if you prefer use the following :

$("#"+popup_form_id).find(":hidden[name='flag']").val( something  );
0
 

Author Comment

by:Nura111
ID: 36713756
Thank you leakim971: Can we go back to the issue form yesterday
 I can post it here or there

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_27325129.html


the function that was handeling the click and that sumbiiting the form
function toggleLeadBody(id) {													
					var fieldName1 = "#spam_"+ id + "_body";
					var fieldName2 = "#sr_" + id + "_body";
					var popup_form_id = "popup_form_" + id;
					 
					var element = $(fieldName2);
                    element.toggle();   
					
					var fElement = $(fieldName1);
				//checking to see if its not been marked as spam	
				if ($(":hidden[name='flag']","#"+popup_form_id).val() =="no"){
					 fElement.toggle();	
					}
    //sumbitting the form			   	    
					fElement.submit(function(e) {
                            alert("Hello world!");
							//fElement.attr('flag','1');
							e.preventDefault();
						//"mark" the input name =flag as spam 
						    $(":hidden[name='flag']","#"+popup_form_id).val("on");
							fElement.toggle();
							
					})                 
					

            }

Open in new window



I attached the form as well

So my only problem is that I want to update the db without changing anything in the page I think I need to use ajax but I dont know hoe to do it without loading anything to the element
<form id = "popup_form_{$row['id']}"  action ="" method ="post" style="background-color:white; border:2px solid blue;padding:4px; width:250px; display :none; position:absolute"  onsubmit = "return false;">

			<input type ="hidden" name="flag" value = "no" >

			<input type="hidden" name="id" value ="{$row['id']}">

			<input type="hidden" name ="email" value ="{$row['email_address']}">

			<input type="submit" value="SpamIt" name="spamIt" style="margin-right:15px;">

			<input type="button" value="Close" onclick="closePopup()"/>

			

			</form>

Open in new window

0
 
LVL 83

Expert Comment

by:leakim971
ID: 36713923
if THIS question is answered you MUST close it.

you may request attention for your other thread : I'm not alone here and not the best.
0
 

Author Comment

by:Nura111
ID: 36713932
ok I just thought you might be intrested you spend quite a while there at that question and I think it will be hard to follow for somebody else
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question