Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

if stament to run a html / jquery code

Posted on 2013-01-22
9
Medium Priority
?
203 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
ID: 38809337
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
ID: 38809616
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
ID: 38809697
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 9

Expert Comment

by:Sar1973
ID: 38809728
You can then inner the new HTML in the other case.
0
 

Author Comment

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

Expert Comment

by:mcnute
ID: 38809865
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
ID: 38809997
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 1400 total points
ID: 38810691
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 600 total points
ID: 38810918
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
Suggested Courses

824 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