• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

if stament to run a html / jquery code

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
eaweb
Asked:
eaweb
  • 3
  • 3
  • 3
2 Solutions
 
Sar1973Commented:
Wht don't you include the whole function inside the statement? This will launch the test at each function trigger/fire.
0
 
mcnuteCommented:
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
 
eawebAuthor Commented:
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

 
Sar1973Commented:
You can then inner the new HTML in the other case.
0
 
eawebAuthor Commented:
how must i modify the code i am using in order not to cause errors
0
 
mcnuteCommented:
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
 
eawebAuthor Commented:
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
 
Sar1973Commented:
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
 
mcnuteCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 3
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now