jQuery append method issue - html

I have a simple jQuery question. I have a Web App that looks like the following:
The HTML for the page is here:
<div id="hwAddition">
<div id="itemNumber" style="text-decoration: underline; font-size: large;">Item #</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="hwDescription" style="text-decoration: underline;">Description</label>
<form:textarea id="hwDescription" type="text"
class="form-control short" path="hwDescription"
name="hwDescription" placeholder="Description" maxlength="100"
rows="2" style="resize: none;" />
</div>
<div class="form-group col-md-4">
<label for="hwSerialNumber" style="text-decoration: underline;">Serial
#</label>
<form:input type="text" class="form-control" path="hwSerialNumber"
name="hwSerialNumber" placeholder="Serial #" maxlength="100" />
</div>
<div class="form-group col-md-4">
<label for="hwModelNumber" style="text-decoration: underline;">Model
#</label>
<form:input type="text" class="form-control" path="hwModelNumber"
name="hwModelNumber" placeholder="Model #" maxlength="100" />
</div>
</div>
<hr />
</div>
</div>
My issue lies with the "Item #" label. I'm trying to simply append a value after the markup so that the labels say "Item #1", "Item #2", and so on. The counting procedure is working and the jQuery is shown here:
var count = 1;
$(function() {
$("#hwAddition").attr('id', 'hwAddition' + count);
$("#itemNumber").attr('id', 'itemNumber' + count);
$("#itemNumber").append(count);
});
$('#hwAdditionButton').click(
function() {
var clonedObj = $("#hwAddition" + count).clone().attr('id', 'hwAddition' + (count+1));
clonedObj.find("#itemNumber" + count).attr('id', 'itemNumber' + (count+1));
clonedObj.insertAfter("#hwAddition" + count);
$("#itemNumber").append(count);
count++;
});
For some reason though, the .append() methods are adding nothing to the end of the labels. What am I doing incorrectly?

At the 5th and 12th rows, you do:
$("#itemNumber").append(count);
You're searching for #itemNumber without a "+ count", if I understand correctly you've changed both the original's and the clone's IDs to be itemNumber + count.
Also, the proper way to append text is:
$('#itemNumber' + count).append(document.createTextNode(count));
But why using append? in your case you can do:
$('#itemNumber' + count).text("Item #" + count);

Related

Angular Js & html

not able to clear the data using angular Js. I have assigned the value to null and empty. when i debug it the values are getting cleared but in front end the values are not clearing
$scope.callCancel = function() {
$scope.riskObj.areaName ="";
$scope.areaName ="";
$scope.riskObj.areaDesc ="";
$scope.areaDesc =""
html code:
<div ng-if="type == 1"class="col-md-3">
<h5><strong>Risk Area Name</strong></h5>
<div class="form-group">
<input type="text" class="form-control input-sm text-field" data-ng-model="areaName" ng-keyup="getChangedAreaName(areaName)" ng-disabled="type == 2">
</div>
</div>
<div ng-if="type == 1" class="col-md-6">
<h5><strong>Risk Area Description</strong></h5>
<div class="form-group">
<input type="text" class="form-control input-sm text-field" data-ng-model="areaDesc" ng-keyup="getChangedAreaDesc(areaDesc)" ng-disabled="type == 2">
</div>
</div>
<div ng-if="type == 1" style="text-align:right;">
<img src="core/static/images/submit-btn.png" data-ng-click="updateRiskArea(areaName,areaDesc,this)" />
<img src="core/static/images/cancel-btn.png" data-ng-click="callCancel()"/>
</div>
I need to clear the values I enter in the front end. Using the above code I am able to clear already entered data. But once I modify the value and call cancel function the values are not getting cleared
The main issue is you're not setting your ng-model accurately. For example, it should bind to riskObj.areaName as that is your data model, not just areaName. Additionally, you should be initializing these objects in your scope somewhere, like $scope.riskObj = {areaName:'', areaDesc:''};
There are a few issues with your code other than that.
Utilize your anchor tags to be ng-click. Don't have an anchor with a hash for HREF and then put an ng-click inside on an image. Instead, just do something like <a href ng-click="...
You have 3 divs in a row with ng-if="type==1" - why not just put those 3 in a <div class="row" ng-if="type==1"> - cleaner and easier to read/maintain
Inside those conditionals, you have a ng-disabled="type==2" -- that will never ever do anything since the div will ONLY show if type=1
angular.module('selectExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.type = 1;
$scope.riskObj = {
areaName: '',
areaDesc: ''
};
$scope.callCancel = function() {
$scope.riskObj.areaName = "";
$scope.areaName = "";
$scope.riskObj.areaDesc = "";
$scope.areaDesc = ""
}
}]);
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.10/angular.min.js"></script>
<div ng-app="selectExample">
<div ng-controller="ExampleController">
<div class='row' ng-if="type == 1">
<div class="col-md-3">
<h5><strong>Risk Area Name</strong></h5>
<div class="form-group">
<input type="text" class="form-control input-sm text-field" data-ng-model="riskObj.areaName">
</div>
</div>
<div class="col-md-6">
<h5><strong>Risk Area Description</strong></h5>
<div class="form-group">
<input type="text" class="form-control input-sm text-field" data-ng-model="riskObj.areaDesc">
</div>
</div>
<div style="text-align:right;">
<a href data-ng-click="callCancel()">cancel</a>
</div>
</div>
</div>

is there any way i could make the first row as mandatory before going to second row in codeigniter?

My view:
<div class="col-md-3">
<div class="form-group">
<label>Employee Id</label>
<input type="text" class="form-control" placeholder="Enter employee id" name="empid">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Employee Name</label>
<input type="text" class="form-control" placeholder="Enter employee name" name="empname">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Order Number</label>
<input type="number" class="form-control" placeholder="Enter order number" name="ordernumber" value="<?php echo $order_number;?>">
</div></div>
<div class="col-md-3">
<div class="form-group">
<label></label>
<a onclick="myFunctionfirst()" class="form-control">Proceed to order Create</a>
</div></div>
Once you click on 'proceed to order create' the second row is created. I want this to happen only when the first 3 fields in first row are filled. Please suggest on this
And this is my controller:
public function index()
{
$empid = $_POST['empid'];
If ($empid == ""){
$this->load->model('invoice_model');
$data['stat']= $this->invoice_model->get_stationary();
$data['order_numbers']= $this->invoice_model->get_countnumber();
$data['order_number']= $data['order_numbers'][0]->count+1;
$data['page']='invoice/invoice_view';
$this->load->view("template",$data);
}
}
And it's throwing an error undefined index empid
Welcome to stackoverflow. what you can do is save the input as a variable Store input from a text field in a PHP variable
this method is however a bit unsafe. to secure the input you can use https://www.w3schools.com/php/func_string_htmlspecialchars.asp
https://www.php.net/manual/en/function.htmlspecialchars.php
and once you have the variables just simply check if the variable is empty or not
public function index()
{
$firstname = $_POST['firstname'];
If ($firstname != ""){
$this->load->model('invoice_model');
$data['stat']= $this->invoice_model->get_stationary();
$data['order_numbers']= $this->invoice_model->get_countnumber();
$data['order_number']= $data['order_numbers'][0]->count+1;
$data['page']='invoice/invoice_view';
$this->load->view("template",$data);
}
}
$_POST is how the data is being send. here they explain the difference between POST and GET https://www.quora.com/What-is-the-difference-between-PHPs-get-method-post-method
'firstname' is the name of the input. in your case its <input type="text" class="form-control" placeholder="Enter employee id" name="empid"> so it should be $_POST['empid']
the data is being send with the submit button. instead of using the <a> tag you should use the <button type="submit"> tag also, wrap the inputs in a form tag.

How can I send form parameters to a mailto link?

I tried the solution at How do I add HTML form data to a mailto link
that did not work in my HTML5 snippet on mobile.
<!-- contact -->
<section id="section-contact" class="section appear clearfix">
<div class="container">
<div class="row mar-bot40">
<div class="col-md-offset-3 col-md-6">
<div class="section-header">
<h2 class="section-heading animated" data-animation="bounceInUp">Contact us</h2>
<p>Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet consectetur, adipisci velit, sed quia non numquam.</p>
</div>
</div>
</div>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div id="sendmessage">Your message has been sent. Thank you!</div>
<div id="errormessage"></div>
<form role="form" class="contactForm">
<div class="form-group">
<input type="text" name="name" class="form-control" id="name" placeholder="Your Name" data-rule="minlen:4" data-msg="Please enter at least 4 chars" />
<div class="validation"></div>
</div>
<div class="form-group">
<input type="email" class="form-control" name="email" id="email" placeholder="Your Email" data-rule="email" data-msg="Please enter a valid email" />
<div class="validation"></div>
</div>
<div class="form-group">
<input type="tel" class="form-control" name="telephone" id="telephone" placeholder="111-111-1111" data-rule="email" data-msg="Please enter a valid telephone number" pattern="[0-9]{3}[0-9]{3}[0-9]{4}" required />
<div class="validation"></div>
</div>
<div class="form-group">
<input type="text" class="form-control" name="subject" id="subject" placeholder="Subject" data-rule="minlen:4" data-msg="Please enter at least 8 chars of subject" />
<div class="validation"></div>
</div>
<div class="form-group">
<textarea class="form-control" name="message" rows="5" data-rule="required" data-msg="Please write something for us" placeholder="Message"></textarea>
<div class="validation"></div>
</div>
<div class="text-center">
<button type="submit" class="line-btn green" onclick="submitForm();return false;">Submit</button>
</div>
</form>
<script>
function submitForm(){
var name = document.getElementsByName("name")[0].value;
var email = document.getElementsByName("email")[0].value;
var phone = document.getElementsByName("telephone")[0].value;
var subject = document.getElementsByName("subject")[0].value;
var message = document.getElementsByName("message")[0].value;
window.open("mailto:denver.prophit#gmail.com?subject=" + encodeURIComponent(subject) +
"&body=Name:%20" + encodeURIComponent(name) +
"%0a%0aTelephone:%20" + encodeURIComponent(phone) +
"%0a%0a" + encodeURIComponent(message));
}
</script>
</div>
</div>
</div>
</section>
What I expected is the gmail app to open. What I got was a scroll back to the top of the page. Not sure what I missed after reading the questions from the previous question posted?
As highlighted by two of us in comments, your javascript is invalid, on this line...
window.open("mailto:example#gmail.com?subject=subject&body=Name:%20:name\n\n+Telephone:%20" + phone\ n\ n + message);
In particular the " + phone\ n\ n + message); part
The fixed version would be...
window.open("mailto:example#gmail.com?subject=subject&body=Name:%20:name\n\n+Telephone:%20" + phone + "\n\n" + message);
This would have been easily spotted by looking at the Console in your Developer Tools (press F12 on your browser) where it would have shown you that there is an error in the javascript.
Additionally the \n will not produce newlines in your email client, so you should use %0a (which is encoded \n) instead...
window.open("mailto:example#gmail.com?subject=subject&body=Name:%20:name%0a%0a+Telephone:%20" + phone + "%0a%0a" + message);
Originally I said use %0d which is the encoded \r... so if you wanted \r\n use %0d%0a
Finally, I believe there are a couple of other minor issues in that line, which will result in the incorrect values being passed through to the email client.
In particular the use of name and the +... and the fact that you're not URI encoding the values, meaning that if any of them have things like ? or & for example, it will mess up the link
This is what I believe you need...
window.open("mailto:example#gmail.com?subject=" + encodeURIComponent(subject) +
"&body=Name:%20" + encodeURIComponent(name) +
"%0a%0aTelephone:%20" + encodeURIComponent(phone) +
"%0a%0a" + encodeURIComponent(message));
I completely missed it, but I think the reason it's going back to the top of the page is that the button click is not being cancelled.
Update the onclick that calls the function to return false...
<button type="submit" class="line-btn green" onclick="submitForm();return false;">Submitx</button>

get HTML value [swift]

I have this set of html:
<div class="container-fluid">
<div class="panel panel-default ">
<div class="panel-body">
<form id="coupon_checkout" action="http://uat.all.com.my/checkout/couponcode" method="post">
<input type="hidden" name="transaction_id" value="4245">
<input type="hidden" name="lang" value="EN">
<input type="hidden" name="devicetype" value="">
<div class="input-group">
<input type="text" class="form-control" id="coupon_code" name="coupon" placeholder="Coupon Code">
<span class="input-group-btn">
<button class="btn btn-primary" type="submit">Enter Code</button>
</span>
</div>
</form>
</div>
</div>
I want to get the transaction id value. How do i get it?
I have try using this code:
var value = wkWebView.evaluateJavaScript("document.getElementByName('transaction_id')", completionHandler: nil)
print("value:\(value)")
But the output is return nothing:
value:( )
Two things - you need an "s" in the getElementsByName code and it returns a collection of elements - you need to specify which - in this case there is only 1, but you still need to specify it and get the value of the element:
...document.getElementsByName('transaction_id')[0].value....
I think it's a typo, you should use getElementsByName instead of getElementByName.
Second thing:
Shouldn't it be "document.getElementsByName('transaction_id').value" rather than "document.getElementByName('transaction_id')"
You can also use it like if heaving issues:
webView.evaluateJavaScript("document.getElementsByName('someElement').value") { (result, error) in
if error != nil {
print(result)
}
}
I have just popped it into this snippet and provided the value in a jquery approach (since you are using Bootstrap - you must also be using jQuery) and the normal javascript method - both work so it must be something to do with the swift content. - also in your output - are you sure that the "\" is not escaping the "("? - should it be print("value:(value)") or escape both print("value:\(value\)") or alter the quotes print("value:"(value))
$(document).ready(function(){
var transaction_idValue1 = $('[name=transaction_id]').val();
console.log(transaction_idValue1);
var transaction_idValue2 = document.getElementsByName('transaction_id')[0].value;
console.log(transaction_idValue2);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container-fluid">
<div class="panel panel-default ">
<div class="panel-body">
<form id="coupon_checkout" action="http://uat.all.com.my/checkout/couponcode" method="post">
<input type="hidden" name="transaction_id" value="4245">
<input type="hidden" name="lang" value="EN">
<input type="hidden" name="devicetype" value="">
<div class="input-group">
<input type="text" class="form-control" id="coupon_code" name="coupon" placeholder="Coupon Code">
<span class="input-group-btn">
<button class="btn btn-primary" type="submit">Enter Code</button>
</span>
</div>
</form>
</div>
</div>
Using SwiftSoup
let html = "<div class=\"container-fluid\">"
+ "<div class=\"panel panel-default \">"
+ "<div class=\"panel-body\">"
+ "<form id=\"coupon_checkout\" action=\"http://uat.all.com.my/checkout/couponcode\" method=\"post\">"
+ "<input type=\"hidden\" name=\"transaction_id\" value=\"4245\">"
+ "<input type=\"hidden\" name=\"lang\" value=\"EN\">"
+ "<input type=\"hidden\" name=\"devicetype\" value=\"\">"
+ "<div class=\"input-group\">"
+ "<input type=\"text\" class=\"form-control\" id=\"coupon_code\" name=\"coupon\" placeholder=\"Coupon Code\">"
+ "<span class=\"input-group-btn\">"
+ "<button class=\"btn btn-primary\" type=\"submit\">Enter Code</button>"
+ "</span>"
+ "</div>"
+ "</form>"
+ "</div>"
+ "</div>"
let document: Document = try SwiftSoup.parse(html);//parse html
let elements = try document.select("[name=transaction_id]")//query
let transaction_id = try elements.get(0)//select first element ,
let value = try transaction_id.val()//get value
print(value)//4245

How can I bind text from text input to another text input using angularjs

I am trying to combine 3 inputs of input text and binding the data to another input text.
<input type="text" class="textbox" name="country" id="loc_country" value="Gershon" ng-model="location.country"/>
<input type="text" class="textbox" name="city" id="loc_city" ng-model="location.city"/>
<input type="text" class="textbox" name="street" id="loc_street" autocomplete="off" ng-model="location.street"/>
<input type="text" class="textbox" name="result" id="result"/>
Here the first 3 inputs need to added to the 4 input automatically with binding
You should set the value HTML attribute of the text box. You can do it inline like so:
<input type="text" class="textbox" name="result" id="result" value="{{location.street + ' ' + location.city + ' ' + location.country}}"/>
Or you can use a computed property. Here is an example:
HTML:
<div ng-app>
<div ng-controller="SomeCtrl">
<input ng-model="textProperty"/>
<input value="{{getCalculatedText()}}"/>
</div>
</div>
JS:
function SomeCtrl($scope) {
$scope.textProperty = "some text";
$scope.getCalculatedText = function() {
return $scope.textProperty+ " is now calculated";};
}
Please see my example answer here: https://jsfiddle.net/em0ney/bc3chrog/2/
function ExampleController($scope) {
$scope.location = {country: 'Australia', city: 'Sydney', street: 'Pitt St'};
$scope.concatLocationComponents = function() {
return $scope.location.street + ' ' + $scope.location.city + ', ' + $scope.location.country;
};
}
Good luck with formatting the result.
Thanks,
Elliott