Solved

if stament to run a html / jquery code

Posted on 2013-01-22
9
185 Views
Last Modified: 2013-03-14
hi, i using the following jquery / html code:
$(document).ready( function (){
	jQuery.get('Wtxt', function(data) {
		var theList = data;
		var arr_theList = theList.split("\n");
		//var newTFOptions = "<option value='000'>Please Choose</option>";
		var arrOptions = ["<option value='000'>Please Choose</option>"];
		for (var x=0; x<arr_theList.length; x++) {
			var arrListItems = arr_theList[x].split("\",\"");
			if (typeof arrListItems[1] != 'undefined') {
				var strText = arrListItems[0].substring(1,arrListItems[0].length);
				var strValue = arrListItems[1].substring(0,arrListItems[1].length-2);

				if (strText != '' && strValue != '') {
					//newTFOptions += "<option value='" + strValue + "'>" + strText + "</option>";
					arrOptions.push("<option value='" + strValue + "'>" + strText + "</option>");
				}
			}
		}		
		$('#RDS').html(arrOptions.join()).trigger("liszt:updated");

		//Value database
		var currentValue = '<#ITM_FIELD dsname="RDS" ds="content">';
		if ( currentValue != '' ) {
			document.getElementById('RDS').value = currentValue;
			$('#RDS').trigger('liszt:updated');
		}
	});
});


</script>

<!-- display wire types -->
<!-- input type="hidden" name="RDS" value="<#itm_text name="itmc2_process_2_desc">" -->
<div class="vf__required group">
    <label for="RDS">Payment Type</label>
	<select id="RDS" name="RDS">
	</select>
    <script>
	jQuery(function ($) {
	    $("select[name='RDS']").addClass("vf__one").css({"height":27});
	});
    </script>
</div>

Open in new window

how can i include the above code in an if statement to work conditionally.
example of what i need is:

if chekvalue == 0005 i want it all to work else don't display in order to be used .
0
Comment
Question by:eaweb
  • 3
  • 3
  • 3
9 Comments
 
LVL 9

Expert Comment

by:Sar1973
Comment Utility
Wht don't you include the whole function inside the statement? This will launch the test at each function trigger/fire.
0
 
LVL 11

Expert Comment

by:mcnute
Comment Utility
Hmm, your problem is to make up an if clause?

if (  checkvalue == '0005' ) {
   // do something here
} else {
   // do another thing here

}

Open in new window

0
 

Author Comment

by:eaweb
Comment Utility
no my problem is:

if checkvalue == '0005'  i  don't want the html label and select to be created.
instead of the select and the label i need a hidden input field to be created

if (  checkvalue == '0005' ) {
   don't create display the label and the select
<label for="RDS">Payment Type</label>
      <select id="RDS" name="RDS">
      </select>
} else {
   create the following hidden field to be submitted with the form
<input type="hidden" name="RDS" value="0004" -->

}

this without creating an error for the jquery script used to populate the select etc...
0
 
LVL 9

Expert Comment

by:Sar1973
Comment Utility
You can then inner the new HTML in the other case.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:eaweb
Comment Utility
how must i modify the code i am using in order not to cause errors
0
 
LVL 11

Expert Comment

by:mcnute
Comment Utility
In the html leave your <div class="vf__required group">... </div>

The next step is the checkvalue. It is not clear out of your description where this value comes from. Is this a value in your text file you are looping there?

Show us the whole page. Best online, or attach it here with the text file. Then we can debug your code effectively. Now we can just guess what's happening.

Right now there is no code which is checking for "checkvalue" in your script so how do we know where to help you there.
0
 

Author Comment

by:eaweb
Comment Utility
Hi, sorry for the missing information.

The checkvalue is a database value. that is why i put a standart number.

i need the if statement for

if (  checkvalue == '0005' ) {
   don't create display the label and the select
<div class="vf__required group">
    <label for="RDS">Payment Type</label>
      <select id="RDS" name="RDS">
      </select>
    <script>
      jQuery(function ($) {
          $("select[name='RDS']").addClass("vf__one").css({"height":27});
      });
    </script>
</div>
} else {
   create the following hidden field to be submitted with the form
<input type="hidden" name="RDS" value="0004" -->

}

this without creating an error for the jquery script used to populate the select etc...
0
 
LVL 9

Accepted Solution

by:
Sar1973 earned 350 total points
Comment Utility
Try to cut and paste this code in the W3 editor:
<!DOCTYPE html>
<html>
<body>

<p>This is some text.</p>

<div id="myDiv" style="color:#0000FF">
  <h3>This is a heading in a div element</h3>
  <p>This is some text in a div element.</p>
</div>
  <input type="submit" value="Submit" onclick="myFunction()">

<p>This is some text.</p>

<script>
 function myFunction() {
  var myHTML=document.getElementById("myDiv").outerHTML;
  var myHTMLAdd="<input type='text' name='LastName' value='Mouse'>";
document.getElementById("myDiv").innerHTML=myHTML+myHTMLAdd;
  }
</script>

</body>
</html>

Open in new window

0
 
LVL 11

Assisted Solution

by:mcnute
mcnute earned 150 total points
Comment Utility
If RDS is not created jquery will throw an error because it cannot find the element and say RDS is undefined.

I would put this section here
 <script>
      jQuery(function ($) {
          $("select[name='RDS']").addClass("vf__one").css({"height":27});
      });
    </script>

Open in new window


together with the part of code which creates the select and the label. Since this is only needed when the label and the RDS select is created. I'm not sure if this is what causes the error but this is an issue which will be there when you have created the if statement and the value is not 0005. For in that case jquery will try modify the height for an element which is not there.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now