Solved

if stament to run a html / jquery code

Posted on 2013-01-22
9
197 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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 350 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 150 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

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.

Question has a verified solution.

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

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
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)
Suggested Courses

636 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